Ext.define('Ext.ux.TreePanelEditor', {
			extend : 'Ext.tree.Panel',
			xtype : 'treePanelEditor',

			// 是否显示上下文菜单
			showContextMenu : true,
			url : null,
			params : null,
			// 右键菜单
			contextMenu : null,
			// 右键菜单项
			contextMenuItems : null,
			// 选择树节点
			selectedNode : null,
			rootVisible : false,
			useArrows: true,

			constructor : function(_cfg) {
				if (!_cfg) {
					_cfg = {};
				}
				Ext.apply(this, _cfg);

				// store加载数据
				this.store = Ext.create('Ext.data.TreeStore', {
							proxy : {
								type : "ajax",
								url : this.url,
								extraParams : this.params
							},
							root : {
								id: '0',
								text : '全部',
								expanded : true
							}
						});
				if(this.showToolbar!==false) { 
					this.tbar = new Ext.Toolbar({
							items : [{
										xtype : 'button',
										iconCls : 'btn-refresh',
										text : '刷新',
										scope : this,
										handler : function() {
											this.store.reload();
										}
									}, {
										xtype : 'button',
										text : '展开',
										iconCls : 'btn-expand',
										scope : this,
										handler : function() {
											this.expandAll();
										}
									}, {
										xtype : 'button',
										text : '收起',
										iconCls : 'btn-collapse',
										scope : this,
										handler : function() {
											this.collapseAll();
										}
									}]
						});
				}
				this.listeners = {
					scope : this,
					'itemclick' : function(view, node) {
						if (this.onclick) {
							this.selectedNode = node;
							var scope = this.scope ? this.scope : this;
							this.onclick.call(scope, view, node);
						}
					},
					'itemdblclick' : function(view, node) {
						if (this.dblclick) {
							this.selectedNode = node;
							var scope = this.scope ? this.scope : this;
							this.dblclick.call(scope, view, node);
						}
					},
					'itemcontextmenu': this.contextHandler
				};
				if (this.contextMenuItems) {
					// 初始化右键的菜单
					this.initContextMenu();
				}
				this.callParent(arguments);
			},// end of constructor

			/**
			 * 右键菜单
			 */
			initContextMenu : function() {
				if (this.showContextMenu) {
					this.contextMenu = new Ext.menu.Menu();
					if (this.contextMenuItems != null) {
						this.contextMenu.add(this.contextMenuItems);
					}
				}
			},
			contextHandler : function(view, node, item, index, e) {
				if(!this.contextMenu) return;
				if (this.treeType == 'org') {
					this.selectedNode = {
								id : node.id,
								text : node.data.text,
								orgType : node.data.orgType
							};
				} else {
					this.selectedNode = {
								id : node.id,
								text : node.data.text
							};
				}

				this.contextMenu.showAt(e.getXY());
			}

		});
